package 樱桃网;

import java.util.Scanner;

public class Main {
    static int N = 100010;

    static int[] p = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 1; i <= n; i++) {
                p[i] = i;
            }
            int cnt = 0;
            while (m-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                int x = find(a), y = find(b);
                if (x != y) {
                    cnt++;
                    p[x] = y;
                }
            }
            System.out.printf("Case #%d: %d\n", cases, 1 * cnt + (n - 1 - cnt) * 2);
        }
    }

    private static int find(int x) {
        if (x != p[x]) {
            p[x] = find(p[x]);
        }
        return p[x];
    }
}


